/*
 * Copyright (c)  2020,  DataPipeline
 * All rights reserved.
 *
 * Id:DefaultSQLIdNameConversion.java   2020-07-16 00:26 wanglijun
 */
package cn.datacare.orm.conversion;

import cn.datacare.orm.util.StringUtils;

import java.lang.reflect.Method;

import static cn.datacare.orm.util.Separator.DOT;
import static cn.datacare.orm.util.Separator.FILE_SEPARATOR;

/**
 * <p>
 * Title SQLIdNameConversion
 * </p>
 * <p>
 * Description:
 * 类名首字母小写＋ 方法名 成为mapper对应的sqlId
 * sqlId 以 "." 区分最后一部分是文件名字，前面转为为文件相对路径
 * </p>
 * <p>
 * Copyright: Copyright (c) 2020
 * </p>
 * <p>
 * Company/Department: DataPipeline
 * </p>
 *
 * @author wanglijun
 * @version 1.0
 * @since 2020-07-16 00:26
 */
public class DefaultSqlIdNameConversion implements SqlIdNameConversion {

    /***
     *
     * @param mapper
     * @param entity
     * @param method
     * @return String
     */
    @Override
    public String getId(Class mapper, Class entity, Method method) {
        String className = StringUtils.unCapitalize(entity.getSimpleName());
        String methodName = method.getName();
        StringBuilder sb = new StringBuilder();
        sb.append(className).append(DOT).append(methodName);
        return sb.toString();
    }

    /***
     * 获取文件路径
     * @param sqlId  sqlId
     * @return String
     */
    @Override
    public String getPath(String sqlId) {
        String modelName = sqlId.substring(0, sqlId.lastIndexOf(DOT));
        //文件路径
        return modelName.replace(DOT, FILE_SEPARATOR);
    }
}
